﻿@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "HistoricalOrders";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<form id="tabGrid">
    <div>
        <table class="form">
            <tr>
                <td class="formValue" style="text-align: center;">
                    姓名：<label id="xm"></label>
                </td>
                <td class="formValue" style="text-align: center;">
                    性别：<label id="xb"></label>
                </td>
                <td class="formValue" style="text-align: center;">
                    入院日期：<label id="ryrq"></label>
                </td>
                <td class="formValue" style="text-align: center;">
                    出院日期：<label id="cyrq"></label>
                </td>
                <td class="formValue" style="text-align: center;">
                    入院诊断：<label id="ryzd"></label>
                </td>
                <td class="formValue" style="text-align: center;">
                    出院诊断：<label id="cyzd"></label>
                </td>
            </tr>
        </table>
    </div>
        <div>
            <table class="form">
                <tr>
                    <th class="formTitle">开始日期：</th>
                    <td class="formValue">
                        <input id="kssj" name="kssj" type="text" class="required form-control input-wdatepicker formClearIgnore" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" value="@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss")">
                    </td>
                    <th class="formTitle">结束日期：</th>
                    <td class="formValue">
                        <input id="jssj" name="jssj" type="text" class="required form-control input-wdatepicker formClearIgnore" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")">
                    </td>
                    <th class="formTitle">长/临医嘱：</th>
                    <td class="formValue">
                        <select id="CLSelect" name="CLSelect"  class="form-control required">
                            <option value="">全部医嘱</option>
                            <option value="临">临时医嘱</option>
                            <option value="长">长期医嘱</option>
                        </select>
                    </td>
                    <th class="formTitle" id="yzlxth" style="display:none">医嘱类型：</th>
                    <td class="formValue" id="yzlxtd" style="display:none">
                        <select id="yzlxSel" name="yzlxSel"  class="form-control required">
                            <option value="2">药品</option>
                            <option value="10">中草药</option>
                            <option value="4">出院带药</option>
                            <option value="3">文字录入</option>
                            <option value="5">项目录入</option>
                        </select>
                    </td>
                    <td class="formValue" style="width:90px;">
                        <input type="button" id="btn_search" onclick="search()" class="btn btn-md btn-primary" style="width:80px;" value="查询" />
                    </td>
                </tr>
            </table>
            <div class="gridPanel">
                <table id="gridList" rel="tabGrid"></table>
                <div id="gridPager"></div>
            </div>
        </div>
</form>

<script>
    var zyh = $.request("zyh");
    var tclx = $.request("tclx");
    var ryrq = $.request("ryrq");
    var xm = $.request("xm");
    var xb = $.request("xb");
    var cyrq = $.request("cyrq");
    var ryzd = $.request("ryzd");
    var cyzd = $.request("cyzd");
    $("#kssj").val(ryrq);
    $("#ryrq").text(ryrq);
    $("#xm").text(xm);
    $("#xb").text(xb);
    $("#cyrq").text(cyrq);
    $("#ryzd").text(ryzd);
    $("#cyzd").text(cyzd);
    var yp = @Html.Raw(((int)EnumYzlx.Yp).ToString());
    var wz = @Html.Raw(((int)EnumYzlx.Wz).ToString());
    var sfxm = @Html.Raw(((int)EnumYzlx.sfxm).ToString());
    var cydy = @Html.Raw(((int)EnumYzlx.Cydy).ToString());
    var ssyz = @Html.Raw(((int)EnumYzlx.ssyz).ToString());
    var zyyz = @Html.Raw(((int)EnumYzlx.zcy).ToString());
    var kfyz = @Html.Raw(((int)EnumYzlx.rehab).ToString());
    function search() {
        $("#gridList").jqGrid('setGridParam', {
            postData: { zyh: zyh, type: tclx==""?  $("#yzlxSel").val():tclx, kssj: $("#kssj").val(), jssj: $("#jssj").val(), cqorls: $("#CLSelect").val()  } 
        }).trigger('reloadGrid');
    }
    $("#CLSelect").change(function () {
        $("#gridList").jqGrid('setGridParam', {
            postData: { zyh: zyh, type: tclx==""?  $("#yzlxSel").val():tclx, kssj: $("#kssj").val(), jssj: $("#jssj").val(), cqorls: $("#CLSelect").val() }
        }).trigger('reloadGrid');
    });
    $("#yzlxSel").change(function () {
        alert(tclx);alert( $("#yzlxSel").val());
        $("#gridList").jqGrid('setGridParam', {
            postData: { zyh: zyh, type: tclx==""?  $("#yzlxSel").val():tclx, kssj: $("#kssj").val(), jssj: $("#jssj").val(), cqorls: $("#CLSelect").val() }
        }).trigger('reloadGrid');
    });
    $(function () {
        if(tclx==""){
            $("#yzlxth").css({"display":""});
            $("#yzlxtd").css({"display":""});
        }
        gridList();
    });
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "@Url.Action("GetHistoricalOrders")",
            postData: { zyh: zyh, type: tclx==""?  $("#yzlxSel").val():tclx, kssj: $("#kssj").val(), jssj: $("#jssj").val(), cqorls: $("#CLSelect").val() },
            height: $(window).height() - 70,
            unwritten: false,
            rownumbers: true,
            multiselect: true,
            colModel: [
                { label: 'Id', name: 'Id', hidden: true },
                { label: '长临', name: 'yzlb', width: 30, align: 'center' },
                { label: '录入时间', name: 'CreateTime', width: 120, align: 'center' },
                { label: '项目代码', name: 'xmdm', width: 10, align: 'left', hidden: true },
                { label: '项目名称', name: 'xmmc', width: 10, align: 'left', hidden: true },
                { label: '医嘱内容', name: 'yznr', width: 240, align: 'left'},
                //{ label: '单价', name: 'dj', width: 60, align: 'left' },
                { label: '剂量', name: 'ypjl', width: 40, align: 'center', hidden: true },
                { label: '用法', name: 'yfmcval', width: 60, align: 'center', hidden: true},
                { label: '用法代码', name: 'ypyfdm', width: 10, align: 'left', hidden: true },
                { label: '每次治疗量', name: 'ypjl', width: 80, align: 'center', hidden: (tclx == sfxm || tclx == kfyz) ? null : true },
                { label: 'pcCode', name: 'pcCode', hidden: true },
                { label: '频次', name: 'pcmc', width: 60, align: 'center', hidden: true},
                { label: '规格', name: 'ypgg', width: 100, align: 'center', hidden: (tclx == yp || tclx == cydy || tclx == zyyz) ? null : true },
                { label: '总量', name: 'sl', width: 40, align: 'center' },
                { label: '单位', name: 'dwwwwwww', width: 40, align: 'center' },
                { label: '部位', name: 'bw', width: 60, align: 'center', hidden: (tclx == sfxm||tclx==kfyz) ? null : true },
    //            {
    //                label: '自备标志', name: 'zbbzzzzzzz', width: 50, align: 'center', hidden: tclx == yp ? null : true, formatter: function (val) {
    //                    return val == 1 ? "是" : "否";
    //                }
    //            },
    //            { label: '嘱托', name: 'ztnr', width: 90, align: 'left' },
    //            { label: '医疗类别', name: 'zfxz', hidden: true },
    //            {
    //                label: '医疗类别', name: 'zfxzmc',width: 50,hidden:(tclx==kfyz)? null:true, formatter: function (cellvalue, a, b) {
    //                    return $.enum.getDescByValue("EnumZiFuXingZhi", b.zfxz);
    //                }
    //            },
                  { label: '库存', name: 'kcsl', width: 50, hidden: true },
                {
                    label: '控制标志', name: 'kzbz', width: 50, hidden: (tclx == yp || tclx == zyyz) ? null : tclx == cydy ? null : true, formatter: function (val) {
                        if (val == "0") {
                            return "正常";
                        } else if (val == "1") {
                            return "禁用"
                        } else if (val == null) {
                            return "";
                        }
                        return val;
                    }
                },
    //            { label: 'jlzhxs', name: 'jlzhxs', hidden: true },
    //            { label: 'zyzhxs', name: 'zyzhxs', hidden: true },
    //            { label: 'qzfs', name: 'qzfs', hidden: true },
    //            { label: 'dwjls', name: 'dwjls', hidden: true }

            ],
            viewrecords: true,
            sortname: 'zh desc',
            loadComplete: function () {
                //var ids = $gridList.getDataIDs();
                //$.each(ids, function () {
                //    var rowid = String(this);
                //    var kcsl = $gridList.jqGrid('getRowData', rowid).kcsl;
                //    var kzbz = $gridList.jqGrid('getRowData', rowid).kzbz;
                //    if ((kcsl != "" && kzbz != "禁用" && (tclx == yp || tclx == zyyz || tclx == cydy)) || (tclx != yp && tclx != cydy && tclx != zyyz)) {
                //        $gridList.jqGrid('setSelection', rowid); //设置jqGrid选中
                //    }
                //});
                //$('#cb_gridList').prop('checked', true);//全选按钮
            },
            onSelectRow: function (rowid, status) {
                if (status && (tclx == yp || tclx == zyyz)) {
                    var kcsl = $gridList.jqGrid('getRowData', rowid).kcsl;
                    var kzbz = $gridList.jqGrid('getRowData', rowid).kzbz;
                    if (kcsl == "") {
                        $.modalAlert("该药品无库存，不可选", "warning");
                        $gridList.jqGrid('setSelection', rowid, false); //设置jqGrid选中
                        return;
                    }
                    if (kzbz == "禁用") {
                        $.modalAlert("该药品禁用状态，不可选", "warning");
                        $gridList.jqGrid('setSelection', rowid, false); //设置jqGrid选中
                        return;
                    }
                }
                //gridztcheck([rowid], status);
            },
            onSelectAll: function (aRowids, status) {
                //gridztcheck(aRowids, status);
            }
        });
    }

    //function gridztcheck(aRowids, status){
    //    CalculateInsPresJYAmount();
    //}

    //计算申请单金额
    //function CalculateInsPresJYAmount() {
    //    var totalAmount = 0.00;
    //    var allData = $("#gridList").jqGrid('getRowData_AllLine', true, true);
    //    $.each(allData, function () {
    //        totalAmount += parseFloat(this.dj) * parseFloat(this.sl);
    //    });
    //    $("#gridList").jqGrid("setCaption", "合计：" + "<label style='color:red;'>￥"
    //        + totalAmount.toFixed(2) + "</label>");   //重置caption属性值
    //}

    function submitForm() {
        var data = $("#gridList").jqGrid('getRowData_AllLine', true, true);
        if(!data || data.length==0){
            $.modalAlert("请选择明细进行复制", 'warning');
            return;
        }
        var yzlistId = "";
        $.each(data, function () {
            for (var i = 0; i < $(this).length; i++) {
                yzlistId = yzlistId + $(this)[i].Id +",";
            }
        });
        return yzlistId;
    }
</script>


